/*
*    UNIVERSIDADE DE SÃO PAULO.
*    Author: Marco Aurélio Gerosa (gerosa@ime.usp.br)
*    This project was/is sponsored by RNP and FAPESP.
*
*    This file is part of Groupware Workbench (http://www.groupwareworkbench.org.br).
*
*    Groupware Workbench is free software: you can redistribute it and/or modify
*    it under the terms of the GNU Lesser General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    Groupware Workbench is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU Lesser General Public License for more details.
*
*    You should have received a copy of the GNU Lesser General Public License
*    along with Swift.  If not, see <http://www.gnu.org/licenses/>.
*/
package br.org.groupwareworkbench.eureka.knowledge;

import java.util.List;

import br.org.groupwareworkbench.collablet.coop.recommend.RecommendMgrInstance;
import br.org.groupwareworkbench.core.framework.AbstractBusiness;
import br.org.groupwareworkbench.core.framework.Collablet;
import br.org.groupwareworkbench.core.framework.annotations.ComponentInfo;
import br.org.groupwareworkbench.core.framework.annotations.DefaultProperty;
import br.org.groupwareworkbench.core.framework.annotations.RequiredDependency;

@ComponentInfo(
    version="0.1",
    configurationURL="/groupware-workbench/knowledge/{knowledgeMgr}/list",
    retrieveURL="/groupware-workbench/knowledge/{id}/show",
    defaultProperties={
        @DefaultProperty(name="numRelatedNews", defaultValue="3"),
        @DefaultProperty(name="qtdCopia", defaultValue="30")
    },
    requiredDependencies=@RequiredDependency(name="recommendMgr", type=RecommendMgrInstance.class)
)
public class KnowledgeMgrInstance extends AbstractBusiness {

    private final CopyFromBD copyFromBD = new CopyFromBD();

    public KnowledgeMgrInstance(Collablet collablet) {
        super(collablet);
    }

    public void copyFromBD() {
        this.copyFromBD.copyFromBD(getCollablet(), Integer.parseInt(getCollablet().getProperty("qtdCopia")));
    }
    
    public List<Knowledge> list() {
        return Knowledge.list(getCollablet());
    }

    public Knowledge findById(long id) {
        return Knowledge.findById(id);
    }

    public void save(Knowledge knowledge) {
        knowledge.setCollablet(getCollablet());
        knowledge.save();
    }
    
    public int getNumRelatedNews() {
        return Integer.parseInt(getCollablet().getProperty("numRelatedNews"));
    }

    public void setNumRelatedNews(int numRelatedNews) {
        getCollablet().setProperty("numRelatedNews", String.valueOf(numRelatedNews));
        getCollablet().save();
    }
}
